<?php
namespace generate\field;

class Icon extends Field
{
    public static $html = <<<EOF
<div class="layui-form-item">
    <label for="[FIELD_NAME]" class="layui-form-label  [REQUIRED]">[FORM_NAME]</label>
    <div class="layui-input-inline">
            <input id="[FIELD_NAME]" name="[FIELD_NAME]" lay-verify="[FORM_VALIDATE]" value="{\$data.[FIELD_NAME]|default='[FIELD_DEFAULT]'}" class="layui-input " placeholder="请选择[FORM_NAME]">
       
    </div>
</div>
<script>
layui.use(['iconPickerFa', 'form', 'layer'], function () {
    var iconPickerFa = layui.iconPickerFa,
        form = layui.form,
        layer = layui.layer,
        $ = layui.$;
        iconPickerFa.render({
        // 选择器，推荐使用input
        elem: '#[FIELD_NAME]',
        url: "__ADMIN_PLUGINS__/font-awesome/less/variables.less",
        // 是否开启搜索：true/false
        search: true,
        // 是否开启分页
        page: true,
        // 每页显示数量，默认12
        limit: 12,
        // 点击回调
        click: function (data) {
            console.log(data);
        },
        // 渲染成功后的回调
        success: function (d) {
            console.log(d);
        }
    });
});
</script>
\n
EOF;

    public static $rules = [
        'required' => '非空',
        'icon'     => '图标',
        'regular'  => '自定义正则'
    ];


    public static function create($data)
    {
        return str_replace(array('[FORM_NAME]', '[FIELD_NAME]', '[FIELD_DEFAULT]', '[FORM_VALIDATE]', '[REQUIRED]'), array($data['form_name'], $data['field_name'], $data['field_default'], self::$verify, self::$required), self::$html);
    }
}